highp float hash(highp vec2 p)
{

    p = fract(p * 0.1031);
    p += dot(p, p + 19.19);
	
    return fract((p.x + p.y) * p.y);
}

highp float noise(highp vec2 p )
{
  highp vec2 i = floor( p );
   highp vec2 f = fract( p );
	highp vec2 u = f*f*(3.0-2.0*f);

    return mix( mix( hash( i ), hash( i + vec2(1.0,0.0) ), u.x),mix( hash( i + vec2(0.0,1.0) ), hash( i + vec2(1.0) ), u.x), u.y);
}

highp float cloudH(highp vec3 xz) {

	highp vec2 xy = xz.xz;

	highp float h = 0.0;
	highp float f = 0.0;
	
    for (float i= 1.0 ;i<10.0;i++) {
        h +=noise(xy*pow(2.6, i))*0.9*pow(0.425, i);
   
    	f = 0.6200*noise( xy ); 
		
		xy = xy*pow(0.5, i);
		f += 0.4000*noise( xy );
		
		xy = xy*pow(0.51, i);
		f -= 0.6000*noise( xy );
		
		xy = xy*pow(0.41, i);
		f += 0.5000*noise( xy );
		
		xy = xy*pow(0.53, i);
		f += 0.7000*noise( xy );
		
		xy = xy*pow(0.45, i);
		f -= 0.6500*noise( xy );
		
		xy = xy*pow(0.55, i);
		f += 0.5800*noise( xy );
		
		xy = xy*pow(0.52, i);
		f -= 0.4500*noise( xy );
		
		
}
	highp float n = f + h;

	return n * smoothstep(1.0, 0.0, pow(max(n - 0.5, 0.0) * (1.0 / (1.0 - 0.5)), FOG_COLOR.a));
}